﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BartonExtension;

namespace IntelligentRouteAssist
{
    public class ZTimeline
    {
        public ZTimeline deadTime { get; set; }
        public int atHour { get; set; }
        public int atMin { get; set; }
        public bool overTime { get; set; }
        public ZTimeline()
        {
            atHour = 0;
            atMin = 0;
            overTime = false;
        }
        public ZTimeline(ZTimeline endTime_)
        {
            atHour = 0;
            atMin = 0;
            overTime = false;
            deadTime = endTime_;
        }
        
        public ZTimeline AddMin(int MinToAdd)
        {
            ZTimeline timeline = new ZTimeline()
                {
                    atHour = this.atHour,
                    atMin = this.atMin,
                    deadTime = this.deadTime
                };
            int AddToHour = MinToAdd / 60;
            int AddToMin = MinToAdd % 60;
            timeline.atHour += AddToHour;
            timeline.atMin += AddToMin;
            if (timeline.atHour >= timeline.deadTime.atHour)
            {
                if (timeline.atMin > timeline.deadTime.atMin)
                {
                    timeline.atMin = timeline.deadTime.atMin;
                    overTime = true;
                }
            }
            return timeline;
        }

        public override string ToString()
        {
            return "{0:00} : {1:00}".FormatWith(atHour, atMin);
        }
            
    }
}
